﻿/*
------------------------------------------
    Rodeo Game Engine
    
    Rodeo Core Module
    Constants.h - header file
    
    This file contains all constants
    

    Copyright(c) Marcin Goryca
------------------------------------------
*/
#ifndef RODEO_CORE_CONSTANTS_H_
#define RODEO_CORE_CONSTANTS_H_

#ifndef RODEO_WINDOWSLIBS_H_
#include "..\windowslibs.h"
#endif    //RODEO_WINDOWSLIBS_H_

#ifndef RODEO_RENDERER_COLORS_H_
#include "renderer\colors.h"
#endif    //RODEO_RENDERER_COLORS_H_

namespace rodeocore
{
const float ONE = 1.0f;
const float ZERO = 0.0f;
const float HALF = 0.5f;
const float NEGATIVE_ONE = -1.0f;

typedef unsigned char* ucp;
typedef unsigned char uc;
typedef unsigned int ui;
typedef short int si;
typedef unsigned short us;
typedef unsigned long ul;

//namespaces

//Default Engine Configuration Values

// Relative\Absolute Path to engine configuration file
const char* const confDefPath = "configuration\\EngineStart.ini";
const char* const configuration_xml = "configuration\\engine_start.xml";

// Default window properties string
const char* const confDefWindowString = "Window";
const char* const confDefWindowWidthKey = "windowWidth";
const char* const confDefWindowHeightKey = "windowHeight";
const char* const confDefScreenDepthKey = "screenDepth";
const char* const confDefScreenFrequencyKey = "screenFrequency";
const char* const confDefFullScreenKey = "fullScreen";
const int confDefWindowWidth = 600;
const int confDefWindowHeight = 400;
const int confDefWindowDepth = 24;
const int confDefWindowFrequency = 60;
const int confDefFullScreen = 0;

//-----------------------------------
// CONSTANTS 3DS (For 3ds Files)
//-----------------------------------

// Every Header in 3DS is 6 bytes long 
// 2 bytes ID and 4 bytes length

// Header of 3DS file
// This chunk contains length of whole 3ds file 
const int MAIN3DS = 0x4D4D;

// Editor version 
const int VERSION = 0x0002;

// Editor Config 
// Here starts all geometry
const int EDITOR = 0x3D3D; 

// Chunk of objects in 3DS file
// In this chunk there are objects: cameras, lights, meshes 
const int MESH = 0x4000;

// Materials
// Holds information about ambient, diffuse, specular color,\n
// texture information, shininess
// Chunk 0xAFFF itself contains no data 
const int MATERIAL = 0xAFFF;

// Editor config (unneeded) 
const int MESHVERSION = 0x3D3E;

//--------------
//    OBJECT's
//--------------

// Triangular Mesh
// There is real data of 3DS file.\n
// This chunk holds a mesh containing triangles 
const int TRIANGLE_POLYGON_MESH = 0x4100;

// Mesh Vertices
// Contains all information about vertices of a mesh 
const int VERTEX_LIST = 0x4110;

// MeshFaces
// Contains the vertex indexes, so the model is solid 
const int FACE_LIST = 0x4120;

// Face Material Info 
const int FACE_MATERIAL = 0x4130;

// Texture Coordinates
// Holds  u, v coordinates of textures for every vertex 
const int UVMAPPING = 0x4140;

// Local axis 
const int AXIS = 0x4160;

//----------------
//    MATERIAL
//----------------

// Material Name 
const int MATERIAL_NAME = 0xA000;

// Ambient Color
// Contains ambient color of the current material.\n
// Subchank 0x0011 contains information of color in RGB format. 
const int MATERIAL_AMBIENT = 0xA010;

// Diffuse
// same as Ambient Color 
const int MATERIAL_DIFFUSE = 0xA020;

// Specular Color
// same as Ambient Color and Diffuse 
const int MATERIAL_SPECULAR = 0xA030;

// Shininess 
const int MATERIAL_SHININESS = 0xA040;

// Transparency 
const int MATERIAL_TRANSPARENCY = 0xA050;

// Texture Map 
const int MATERIAL_TEXTURE_MAP = 0xA200;

// Texture Map Filename 
const int MATERIAL_TEXTURE_FILENAME = 0xA300;

//--------------------
//    ANIMATION
//--------------------

// Keyframe data 
const int KEYFRAME = 0xB000;

// Mesh anim data 
const int ANIMOBJECT = 0xB002;

// Number of keyframes 
const int FRAMES = 0xB008;

// Object parameters for animation 
const int PARAM = 0xB010;

// Object pivot point 
const int PIVOT = 0xB013;

// Object hierarchy position 
const int HIERARCHY = 0xB030;

// Track position 
const int POSITON = 0xB020;

// Track rotation 
const int ROTATION = 0xB021;

// Track scale 
const int SCALE = 0xB022;

//------------
//    TODO
//------------

const int KFVERSION = 0x0005;
const int COLORF = 0x0010;
const int COLOR24 = 0x0011;
const int LINCOLOR24 = 0x0012;
const int LINCOLORF = 0x0013;
const int INTPERCENTAGE = 0x0030;
const int FLOATPERC = 0x0031;
const int MASTERSCALE = 0x0100;
const int IMAGEFILE = 0x1100;
const int AMBIENTLIGHT = 0x2100;
const int VERTEXFLAGS = 0x4111;

const int MESHCOLORIND = 0x4165;
const int MESHTEXTUREINFO = 0x4170;
//const int HIERARCHY = 0x4F00;
const int MATERIALFALLOFF = 0xA052;
const int MATERIALEMMISIVE = 0xA080;
const int MATERIALSHADER = 0xA100;
const int OBJECTLIGHT = 0x4600;
const int OBJECTCAMERA = 0x4700;
const int ANIMHEADER = 0xB00A;

//--------------------------
//    DDS_PIXELFORMAT flags
//---------------------------

// texture contains alpha data;
// rgbAlphaBitMask contains valid data 
#define DDPF_ALPHAPIXELS    0x1

// used in older files for alpha channel only uncompressed data 
// (rgbBitCount contains the alpha channel bitcount, aBitMask contains valid data) 
#define DDPF_ALPHA    0x2

// texture contains compressed RGB data,
// fourcc contains valid data 
#define DDPF_FOURCC    0x4

// texture contains uncompressed RGB data, 
// rgbBitCount and the RGB masks (rBitMask, gBitMask, bBitMask)
// contain  valid data
#define DDPF_RGB    0x40

// used in older files for YUV uncompressed data 
// (rgbBitCount contains the YUV bit count,
// rBitMask contains the Y mask,
// gBitMask U mask,
// bBitMask V mask)
#define DDPF_YUV    0x200

// used in older files for single channel color uncompressed data 
// (rgbBitCount contains the luminance channel bit count,
// rBitMask contains the channel mask).
// Can be combined  with DDPD_ALPHAPIXELS for two channel file 
#define DDPF_LUMINANCE    0x20000

//------------------------
//    DDS_HEADER flags 
//------------------------

// required 
#define DDSH_CAPS    0x1

// required 
#define DDSH_HEIGHT    0x2

// required 
#define DDSH_WIDTH    0x4

// required when pitch is provided for an uncompressed texture 
#define DDSH_PITCH    0x8

// required
#define DDSH_PIXELFORMAT    0x1000

// required in a mipmapped texture 
#define DDSH_MIPMAPCOUNT	0x20000

// required when pitch is provided for compressed texture
#define DDSH_LINEARSIZE    0x80000

// required in depth texture
#define DDSH_DEPTH			0x800000

//--------------------------
//    DDS_HEADER caps 
//--------------------------

// Optional, must be used on any file that contains more than one surface
// (mipmap, cubic environment map, mipmapped volume texture)
#define DDSCAPS_COMPLEX    0x8

// Optional, should be used for mipmap
#define DDSCAPS_MIPMAP    0x400000

// Required
#define DDSCAPS_TEXTURE    0x1000

// DDS_HEADER caps2

// required for a cubemap
#define DDSCAPS2_CUBEMAP    0x200

// required when these surfaces are stored in a cube map
#define DDSCAPS2_CUBEMAP_POSITIVEX    0x400
#define DDSCAPS2_CUBEMAP_NEGATIVEX    0x800
#define DDSCAPS2_CUBEMAP_POSITIVEY    0x1000
#define DDSCAPS2_CUBEMAP_NEGATIVEY    0x2000
#define DDSCAPS2_CUBEMAP_POSITIVEZ    0x4000
#define DDSCAPS2_CUBEMAP_NEGATIVEZ    0x8000

// required for a volume texture
#define DDSCAPS2_VOLUME    0x200000
#define DDSD_CAPS    0x00000001l

#ifndef MAKEFOURCC
    #define MAKEFOURCC(ch0, ch1, ch2, ch3)                              \
                ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) |   \
                ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))
#endif //defined(MAKEFOURCC)


//----------------------------------------------------
// FOURCC codes for DX compressed-texture pixel formats
//----------------------------------------------------
#define FOURCC_DXT1  (MAKEFOURCC('D','X','T','1'))
#define FOURCC_DXT2  (MAKEFOURCC('D','X','T','2'))
#define FOURCC_DXT3  (MAKEFOURCC('D','X','T','3'))
#define FOURCC_DXT4  (MAKEFOURCC('D','X','T','4'))
#define FOURCC_DXT5  (MAKEFOURCC('D','X','T','5'))


struct DDS_PIXELFORMAT
{
    ui size;
    ui flags;
    ui fourCC;
    ui rgbBitCount;
    ui rBitMask;
    ui gBitMask;
    ui bBitMask;
    ui aBitMask;
};

struct DDS_HEADER
{
    ui size;
    ui flags;
    ui height;
    ui width;
    ui pitchOrLinearSize;
    ui depth;
    ui mipMapCount;
    ui reserved1[11];
    DDS_PIXELFORMAT ddspf;
    ui caps;
    ui caps2;
    ui caps3;
    ui caps4;
    ui reserved2;
};

// This is helper structure for flipping the image
struct DXTColors
{
    us r, g, b, a;
};

// ALL IN-ENGINE ASSETS

// Engine Window Icons - DO NOT MODIFY!
const std::string iconAssetPath = "assets\\icons\\rrbi-32.ico";
const std::string iconSmAssetPath = "assets\\icons\\rrbi-16.ico";

// RAW FILES - TERRAIN DATA
const char* const kMap1_raw = "assets\\heightmaps\\map1.raw";

// AUDIO FILES
const char* const kMm9_mp3 = "assets\\audio\\mm9.mp3";

// FONT MEDIA PATH
const char* const fonts_path = "assets\\fonts";

// SHADERS TYPE - VERTEX SHADER, FRAGMENT SHADER
enum ShaderType { RODEO_VS, RODEO_FS };

// SHADERS VENDOR - GLSL, CG
enum ShadersVendor { RODEO_GLSL, RODEO_CG };

// Maximum amount of objects on the scene
const ui MAX_OBJECTS_ = 100;

//
//enum DrawStyle
//{
//    RODEO_FILL = GLU_FILL,
//    RODEO_LINE = GLU_LINE,
//    RODEO_POINT = GLU_POINT,
//    RODEO_SILHOUETTE = GLU_SILHOUETTE
//};
//
//enum Normals
//{
//    RODEO_NONE = GLU_NONE,
//    RODEO_SMOOTH = GLU_SMOOTH,
//    RODEO_FLAT = GLU_FLAT
//};
//
//enum Orientation
//{
//    RODEO_OUTSIDE = GLU_OUTSIDE,
//    RODEO_INSIDE = GLU_INSIDE
//};

//-----------------
//    MATH
//-----------------

const float RODEO_PI = 3.14159265f;
const float RODEO_TWOPI = 6.2831852f;
const float RODEO_HALFPI = 1.5707963f;
const float RODEO_ONEBYPI = 1.0f / RODEO_PI;
const float RODEO_ONEBY2PI = 1.0f / RODEO_TWOPI;
const ui RODEO_FULL_CIRCLE = 360;

// DEGREE - Degrees From Radians [180 / PI] 
const float RODEO_DEGREE = 57.2957f;
const float RODEO_RADIAN = 0.01745f;

enum RendererType 
{
    RODEO_DX, RODEO_GL
};

}    //end of rodeocore namespace

#endif    //RODEO_CORE_CONSTANTS_H_